﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HR.Appointments.Service;
using HR.Appointments.Service.ValueObjects;

public partial class OpenHours : EmployeePage
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckCredentials();
        _imgConfirm.Visible = IsLoggedIn;
    }

	protected void _btnConfirm_Click(object sender, EventArgs e)
	{
        System.Diagnostics.Debug.Assert(_rblWorkorAllDays.Items.Count >= 2, "List has to have atleast 2 items.");
        try
        {
            var from = TimeUnit.Create(_ddlFromHours.SelectedValue + ":" + _ddlFromMinutes.SelectedValue);
            var to = TimeUnit.Create(_ddlToHours.SelectedValue + ":" + _ddlToMinutes.SelectedValue);

            if (from.CompareTo(to) > 0)
            {
                _ErrorOpenHours.Text = "Ólögleg tímasetning";
                return;
            }
            Facade.Employee().UpdateOpenHours(
                GetCompanyIdFromCookie(),
                TimeUnit.Create(_ddlFromHours.Text + ":" + _ddlFromMinutes.Text),
                TimeUnit.Create(_ddlToHours.Text + ":" + _ddlToMinutes.Text),
                _rblWorkorAllDays.Items[1].Selected);
        }
        catch (SubmitException)
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "ErrorAlert", "alert('Ekki tókst að uppfæra.');", true);
        }
		Server.Transfer("~/DisplayOpenHours.aspx");
    }
    #endregion

    #region Link Transfer
    protected void _ibmHomePage_Click(object sender, ImageClickEventArgs e)
    {
        if (!IsPostBack || (e.X != 0 && e.Y != 0))
        {
            Server.Transfer("~/Company.aspx", true);
        }
    }
    protected void _lbtnCompanyBooking_Click(object sender, EventArgs e)
    {
        Server.Transfer("~/Config.aspx", true);
    }
    
	protected void _lbtnConfig_Click(object sender, EventArgs e)
	{
		Server.Transfer("~/Config.aspx", true);
    }
    
	protected void _lbtnCompanyBooking2_Click(object sender, EventArgs e)
	{
		Server.Transfer("~/CompanyBooking.aspx", true);
    }
    #endregion
}
